package com.dlc.shop.api.controller;

import com.dlc.shop.bean.app.dto.IndexImgDto;
import com.dlc.shop.bean.model.IndexImg;
import com.dlc.shop.common.response.ServerResponseEntity;
import com.dlc.shop.common.util.BeanUtil;
import com.dlc.shop.service.IndexImgService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author LGH
 */
@RestController
@Tag(name = "首页轮播图接口")
@AllArgsConstructor
public class IndexImgController {



    private final IndexImgService indexImgService;

    @GetMapping("/indexImgs/{shopId}")
    @Operation(summary = "首页轮播图" , description = "获取首页轮播图列表信息")
    @Parameters({
            @Parameter(name = "shopId", description = "店铺id" , required = true),
            @Parameter(name = "imgType", description = "图片类型" )
    })
    public ServerResponseEntity<List<IndexImgDto>> indexImgs(@PathVariable("shopId") Long shopId,
                                                       @RequestParam(required = false, defaultValue = "0") Integer imgType) {
        List<IndexImg> indexImgList = indexImgService.listIndexImgsByShopId(shopId, imgType);
        List<IndexImgDto> indexImgDtos = BeanUtil.mapAsList(indexImgList, IndexImgDto.class);
        return ServerResponseEntity.success(indexImgDtos);
    }
}
